package com.zpphis.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zpphis.entity.Drugs;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author zpp
 * @since 2022-11-22
 */
@Mapper
public interface DrugsMapper extends BaseMapper<Drugs> {

    @Select("SELECT\n" +
            "\td.*, c1.constant_name `drugsDosage`,\n" +
            "\tc2.constant_name `drugsType`\n" +
            "FROM\n" +
            "\tt_drugs d\n" +
            "INNER JOIN t_constant_item c1 ON d.drugs_dosage_id = c1.id\n" +
            "INNER JOIN t_constant_item c2 ON d.drugs_type_id = c2.id\n" +
            "WHERE\n" +
            "\td.del_mark = 1\n" +
            "AND (\n" +
            "\td.drugs_code LIKE #{queryString}\n" +
            "\tOR d.drugs_name LIKE #{queryString}\n" +
            "\tOR d.manufacturer LIKE #{queryString}\n" +
            "\tOR d.mnemonic_code LIKE #{queryString}\n" +
            ")")
    Page<Map<String, Object>> selectMapsPage(Page<Map<String, Object>> p, String queryString);
}
